package com.hadoop.project.mvc.service.impl;

import com.hadoop.project.entity.po.VideoRank;
import com.hadoop.project.entity.query.SimplePage;
import com.hadoop.project.entity.query.VideoRankQuery;
import com.hadoop.project.entity.vo.PaginationResultVO;
import com.hadoop.project.entity.enums.PageSize;
import com.hadoop.project.mvc.mappers.VideoRankMapper;
import com.hadoop.project.mvc.service.VideoRankService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: Service Impl
 * @author:alexmaodali
 * @date:2025/4/14
 */
@Service("videoRankService")
public class VideoRankServiceImpl implements VideoRankService {

	@Resource
	private VideoRankMapper<VideoRank,VideoRankQuery> videoRankMapper;

	/**
	 * 根据条件查询列表
	 */
	public List<VideoRank> findListByQuery(VideoRankQuery query) {
		return this.videoRankMapper.selectList(query);
	}

	/**
	 * 根据条件查询数量
	 */
	public Integer findCountByQuery(VideoRankQuery query) {
		return this.videoRankMapper.selectCount(query);
	}

	/**
	 * 分页查询
	 */
	public PaginationResultVO<VideoRank> findListByPage(VideoRankQuery query) {
		Integer count = this.findCountByQuery(query);
		Integer pageSize = query.getPageSize() == null ? PageSize.SIZE_ALL.getSize() : query.getPageSize();
		SimplePage page = new SimplePage(query.getPageNo(), count, pageSize);
		query.setSimplePage(page);
		List<VideoRank> list = this.videoRankMapper.selectList(query);
		PaginationResultVO<VideoRank> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
		return result;
	}


	/**
	 * 新增
	 */
	public Integer add(VideoRank bean) {
		return this.videoRankMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	public Integer addBatch(List<VideoRank> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			 return 0;
		}
		return this.videoRankMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或修改
	 */
	public Integer addOrUpdateBatch(List<VideoRank> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			 return 0;
		}
		return this.videoRankMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 根据Id查询
	 */
	public VideoRank getVideoRankById(Long id) {
		return this.videoRankMapper.selectById(id);
	}

	/**
	 * 根据Id更新
	 */
	public Integer updateVideoRankById(VideoRank bean,Long id) {
		return this.videoRankMapper.updateById(bean,id);
	}

	/**
	 * 根据Id删除
	 */
	public Integer deleteVideoRankById(Long id) {
		return this.videoRankMapper.deleteById(id);
	}


}
